import {delay, toast} from "../../utils/tool";
import {WEEK_ENUM} from "../../constant/index";
import EventBus from "../../utils/eventBus";

const app = getApp();

const ONE_HOUR_VALUE = 1000 * 60 * 60
Page({
    data: {
        payMethodMenu: [ // 支付方式
            {label: '微信支付', icon: '/images/wx.png', value: 2},
            // {label: '团购验券', icon: '/assets/img/dy-mt.png', value: 3},
            // {label: '余额支付', icon: '/images/yue.png', value: 1}
        ],
        newPrice: '0.00',
        couponMoney: '0.00',
        useCoupon: false, // 是否是有了优惠券
        payOption: [{label: "微信支付", disabled: false, value: 2,}, {label: '余额支付', disabled: false, value: 1}],
        payType: 2, // 选择的支付方式
        showPayMethod: false,
        userMoney: '0.00', // 用户余额
        weekData: [], // 日期
        totalPrice: '0.00', // 订单总价
        couponList: [], // 优惠券列表
        activeCoupon: null,  // 当前选中的优惠券
        couponText: '未选择优惠券', // 优惠券提示词
        activeMeal: 0, // 当前选中的套餐
        mealOptions: [], // 套餐列表
        confirmType: 0, // 选择模式 0->套餐 1->小时
        showHourVisible: false,
        timeDuration: 0,
        timeColumns: [],
        timePop: false,
        start_time: '00:00', // 开始时间 text
        end_time: '00:00', // 结束时间 text
        start_time_value: 0, // 开始时间时间戳
        end_time_value: 0, // 结束时间时间戳
        currentHour: 0, // 选中小时数
        store: {},
        // 可选择小时数
        timeList: [],
        activeTimeID: 0,
        // activeTimeText: '2',
        roomdetail: {}, //上个页面带来的数据
        bindEvent: false, // 是否绑定了更新余额的事件
        otherTimeColumn: [], //其他时间列表
        otherLabel: '其他',
        minHour: '',
    },
    selectOtherTimeChange(ev) {
        const index = ev.detail.value * 1
        const {otherTimeColumn} = this.data
        const target = otherTimeColumn[index]
        if (!target) return
        const {value} = target
        const {roomdetail: {price}} = this.data
        const totalPrice = (value * price).toFixed(2)
        const {start_time_value} = this.data
        // const _time = start_time_value + ((1000 * 60 * 60) * value)
        // const date = new Date(_time)
        // const [h, m] = [date.getHours(), date.getMinutes()]
        // const str = `${h < 10 ? '0' + h : h}:${m < 10 ? '0' + m : m}`
        const {end_time_value, end_time} = this.getEndTime(start_time_value, value)
        this.setData({
            totalPrice,
            activeTimeID: -1,
            otherLabel: `${value}h`,
            // activeTimeText: `${value}小时`,
            end_time_value,
            end_time,
            currentHour: value,
        })
    },
    initOtherTimeList(max) {
        const result = []
        for (let i = max; i < 25; i++) {
            result.push({
                label: `${i}小时`,
                value: i,
            })
        }
        this.setData({
            otherTimeColumn: result
        })
    },
    changPayType(ev) {
        const {value} = ev.currentTarget.dataset
        if (value === this.data.payType) return
        this.setData({
            payType: value
        })
    },
    choseTypeConfirm(ev) {
        const {detail: index} = ev
        const {payOption, payType} = this.data
        const target = payOption[index]
        if (!target || payType === target.value) return this.chosePayTypeCancel()
        this.setData({
            payType: target.value,
            showPayMethod: false
        })
    },
    chosePayTypeCancel() {
        this.setData({
            showPayMethod: false,
        })
    },
    updateMoney(userData) {
        if (!!userData) return
        const {money} = userData
        this.setData({
            userMoney: money,
        })
    },
    // 去充值
    toUserAccount() {
        if (!this.data.bindEvent) {
            this.data.bindEvent = true
            EventBus.$on('accountSuccess', this.updateMoney)
        }
        wx.navigateTo({
            url: '/pages/wallet/wallet?event=account',
        })
    },
    getTotalPrice() {
        const {currentHour, roomdetail, confirmType} = this.data
        if (confirmType === 1) return currentHour * roomdetail.price
        return this.data.totalPrice
    },
    useCouponHandler() {
        const {couponList, activeCoupon} = this.data
        wx.navigateTo({
            url: '/pages/chose-coupon/chose-coupon',
            success: event => {
                event.eventChannel.emit('initData', {
                    price: this.getTotalPrice(),
                    list: couponList,
                    active: activeCoupon
                })
            },
            events: {
                choseCoupon: res => {
                    const {totalPrice} = this.data
                    if (!!res) {
                        const {money} = res
                        const value = totalPrice - money
                        return this.setData({
                            couponText: `使用${money}元优惠券`,
                            activeCoupon: res,
                            useCoupon: true,
                            couponMoney: money.toFixed(2),
                            newPrice: value.toFixed(2)
                        })
                    }
                    this.setData({
                        couponText: `未使用优惠券`,
                        activeCoupon: null,
                        useCoupon: false,
                        couponMoney: '0.00',
                        newPrice: '0.00'
                    })
                }
            }
        })
    },
    changeTimeByMeal(index) {
        const {mealOptions, weekData, start_time} = this.data
        if (!mealOptions.length) return
        const targetDate = weekData.find(item => item.active)
        if (!targetDate) return toast({title: '选择日期错误'})
        const {_date} = targetDate
        const currentDate = new Date(`${_date} ${start_time}`)
        const targetMeal = mealOptions[index]
        if (!targetMeal) return
        const {time, price} = targetMeal
        const new_time_value = currentDate.getTime() + (ONE_HOUR_VALUE * time)
        const {text} = this.formatTime(new_time_value, false)
        this.setData({
            totalPrice: Number(price),
            currentHour: time,
            end_time_value: new_time_value,
            end_time: text,
        })
    },
    changeTimeBySelectHour() {
        const {activeTimeID, timeList, weekData, start_time, roomdetail} = this.data
        const {price} = roomdetail
        const target = timeList.find(item => item.value === activeTimeID)
        const targetWeek = weekData.find(item => item.active)
        if (!targetWeek) return toast({title: '时间选择错误'})
        let hour = target.value
        const {_date} = targetWeek
        const currentDate = new Date(`${_date} ${start_time}`)
        const new_time_value = currentDate.getTime() + (ONE_HOUR_VALUE * hour)
        const {text} = this.formatTime(new_time_value, false)
        this.setData({
            totalPrice: (price * hour).toFixed(2),
            end_time: text,
            currentHour: hour,
            end_time_value: new_time_value,
        })
    },
    changeMeal(ev) {
        const {index} = ev.currentTarget.dataset
        if (this.data.activeMeal === index) return
        this.setData({
            activeMeal: index
        })
        this.changeTimeByMeal(index)
    },
    tabChange(ev) {
        const {index} = ev.detail
        this.setData({
            confirmType: index
        })
        if (index === 0) return this.changeTimeBySelectHour()
        this.changeTimeByMeal(this.data.activeMeal)
    },
    // selectTimeConfirm(ev) {
    //     const {detail: value} = ev
    //     const {roomdetail: {price}} = this.data
    //     const totalPrice = (value * price).toFixed(2)
    //     const {start_time_value, timeList} = this.data
    //     const _time = start_time_value + ((1000 * 60 * 60) * value)
    //     const date = new Date(_time)
    //     const [h, m] = [date.getHours(), date.getMinutes()]
    //     const str = `${h < 10 ? '0' + h : h}:${m < 10 ? '0' + m : m}`
    //     timeList[timeList.length - 1].label = `${value}h`
    //     this.setData({
    //         otherLabel: '其他',
    //         totalPrice,
    //         timeList: [...timeList],
    //         activeTimeID: 1,
    //         activeTimeText: `${value}小时`,
    //         end_time_value: _time,
    //         end_time: str,
    //         currentHour: value,
    //         showHourVisible: false
    //     })
    // },
    otherTime() {
        // this.setData({
        //     showHourVisible: true
        // })
    },
    openTimePopup() {
        this.setData({
            timePop: true
        })
    },
    selectTimeCancel() {
        this.setData({
            showHourVisible: false
        })
    },
    choseTimeHand(ev) {
        const {id} = ev.currentTarget.dataset
        const {activeTimeID, timeList} = this.data
        if (activeTimeID === id) return
        const target = timeList.find(item => item.value === id)
        const {value} = target
        const {roomdetail: {price}} = this.data
        let totalPrice = (price * value).toFixed(2)
        const {start_time_value} = this.data
        const _time = start_time_value + ((1000 * 60 * 60) * target.value)
        const date = new Date(_time)
        const [h, m] = [date.getHours(), date.getMinutes()]
        const str = `${h < 10 ? '0' + h : h}:${m < 10 ? '0' + m : m}`
        this.setData({
            totalPrice,
            activeTimeID: id,
            end_time_value: _time,
            end_time: str,
            currentHour: value,
            otherLabel: '其他',
            // timeList: [...timeList],
            // activeTimeText: target.label,
        })
    },
    changeWeekHand(ev) {
        let {index} = ev.currentTarget.dataset
        index *= 1
        const {weekData} = this.data
        const currentIndex = weekData.findIndex(item => item.active)
        if (currentIndex === index) return
        weekData[currentIndex].active = false
        weekData[index].active = true
        this.setData({
            weekData: [...weekData]
        })
        const target = weekData[index]
        this.initColumn(new Date(target.fullTime).getTime(), true)
    },
    formatDate(time, isNow = false) {
        const date = new Date(time)
        const [y, m, d, w] = [date.getFullYear(), date.getMonth() + 1, date.getDate(), date.getDay()]
        let text = ''
        let fullTime = `${y}/${m}/${d}`
        let _date = fullTime
        if (isNow) {
            text = '今天'
            const [hour, minute] = [date.getHours(), date.getMinutes()]
            fullTime += ` ${hour < 10 ? '0' + hour : hour}:${minute < 10 ? '0' + minute : minute}`
        } else {
            text = WEEK_ENUM[w]
        }
        return {
            date: `${m >= 10 ? m : '0' + m}.${d >= 10 ? d : '0' + d}`,
            text,
            fullTime,
            active: isNow,
            _date,
        }
    },
    initWeekData() {
        const now = Date.now()
        const result = []
        const oneDay = 24 * 60 * 60 * 1000
        for (let i = 0; i < 5; i++) {
            result.push(this.formatDate(now + (oneDay * i), i === 0))
        }
        this.setData({weekData: result})
    },
    // 门店使用教程
    jiaocheng() {
        wx.navigateTo({
            url: '/pages/jiaocheng/jiaocheng',
        })
    },
    onChange(event) {
    },
    book: function (e) {
        var id = e.currentTarget.dataset.id;
        wx.navigateTo({
            url: '/pages/book/book?id=' + id
        })
    },
    getStartDate() {
        const {weekData, start_time} = this.data
        const targetDay = weekData.find(item => item.active)
        if (!targetDay) return toast({title: "时间选择错误"})
        const {_date} = targetDay
        return `${_date} ${start_time}`
    },
    cancelOrder(order_id) {
        app.ajax({
            url: "/api/user/canalOrder",
            data: {order_id},
            success: (resp) => {
                console.log(resp, '取消订单')
            }
        })
    },
    wxPay(data) {
        wx.requestPayment({
            nonceStr: data.nonceStr,
            package: data.package,
            paySign: data.paySign,
            timeStamp: data.timeStamp,
            signType: data.signType,
            success: () => {
                wx.switchTab({
                    url: '/pages/my-order/my-order'
                })
            },
            fail: () => {
                this.cancelOrder(data.order_id)
                toast({title: '支付失败'})
            }
        })
    },
    accountPay(code, msg) {
        toast({title: msg}, () => {
            if (code === 1) {
                wx.switchTab({
                    url: '/pages/my-order/my-order'
                })
                app.updateUserInfo().then(data => {
                    const {money} = data
                    this.setData({
                        userMoney: money
                    })
                })
            }
        })
    },
    couponPay(data) {
        const {order_id, nums} = data
        wx.navigateTo({
            // url: `/pages/meituan/meituan?num=${nums}&orderID=${order_id}`
            url: `/pages/group-buying/group-buying?type=${2}&order_id=${order_id}&nums=${nums}`
        })
    },
    preConfirmOrder(payload) {
        const disclaimer = wx.getStorageSync('disclaimer')
        wx.showModal({
            title: '免责声明',
            content: disclaimer,
            cancelText: "取消",
            confirmText: "同意", //默认是“确定”
            success: ({cancel}) => {
                if (cancel) return
                wx.requestSubscribeMessage({
                    'tmplIds': [
                        'LPRQriYCiz0M_8SC1B35MxXwfF9NPR15rTO5UK7-V98',
                        'ILerHD6MYqAyGnyJ_AeVFSlqEMguQ24cTaT59Xot4Sw',
                        'mCcWRiaJcHNjX4A2WBu-ugdeD08yVZo7rFUBc5UptEc'
                    ],
                    complete: () => {
                        app.ajax({
                            url: '/api/user/addorder',
                            data: payload,
                            success: res => {
                                const {code, data, msg} = res
                                if (code !== 1) return toast({title: msg})
                                if (data.hasOwnProperty('appId')) return this.wxPay(data)  // 微信支付
                                if (data.hasOwnProperty('order_id')) return this.couponPay(data) // 验券
                                this.accountPay(code, msg) // 余额支付
                            }
                        })
                    }
                })
            }
        })
    },
    getCurrentDate() {
        const date = new Date()
        const [year, month, day, hour, minute] = [date.getFullYear(), date.getMonth() + 1, date.getDate(), date.getHours(), date.getMinutes()]

        function patchZero(v) {
            return ('0' + v).slice(-2)
        }

        return `${year}-${patchZero(month)}-${patchZero(day)} ${patchZero(hour)}:${patchZero(minute)}`
    },
    addOrderHandler() {
        const hasMobile = app.checkHasMobile(false)
        if (!hasMobile) return wx.showModal({
            title: '温馨提示',
            content: '您的账号未绑定手机号,请授权绑定!',
            showCancel: true,
            cancelText: "取消",
            success: ev => {
                if (ev.cancel) return
                wx.navigateTo({url: "/pages/login/login"})
            }
        })
        const {
            currentHour,
            confirmType,
            roomdetail,
            mealOptions,
            activeMeal,
            payType,
            activeCoupon,
            useCoupon
        } = this.data
        // const date = this.getStartDate()
        const isMeal = confirmType === 1
        // if (currentHour < 2 && !isMeal) return toast({title: "预定时间2小时起"})
        const payload = {
            room_id: roomdetail.id,
            date: this.getCurrentDate(),
            nums: currentHour,
            is_taocan: isMeal ? 1 : 2,
            pay_type: payType,
            order_type: 2,
        }
        if (useCoupon && confirmType !== 3) {
            payload.coupon_id = activeCoupon.coupon_id
        }
        if (isMeal) {
            if (!mealOptions.length) return wx.showModal({
                title: '提醒',
                content: '当前包间暂未设置套餐,请切换预付模式!',
                showCancel: false,
            })
            const targetMeal = mealOptions[activeMeal]
            if (!targetMeal) return toast({title: '套餐选择有误'})
            payload.taocan_id = targetMeal.id
        }
        return this.preConfirmOrder(payload)
    },

    formatTime(time, should = true) {
        if (should) {
            time *= 1000
        }
        const date = new Date(time)
        const [h, m] = [date.getHours(), date.getMinutes()]
        const text = `${h < 10 ? '0' + h : h}:${m < 10 ? '0' + m : m}`
        return {
            text,
            value: date.getTime(),
        }
    },
    getDuration(time) {
        const oneDay = 1000 * 60 * 60
        const {timeList} = this.data
        const target = timeList.find(item => {
            return oneDay * item.value === time
        })
        if (target) return target.value
        return 0
    },
    pickerChangeHandle(ev) {
        const [hourIndex, minuteIndex] = ev.detail.value
        const {timeColumns, currentHour} = this.data
        const [hourList, minuteList] = timeColumns
        const targetHour = hourList[hourIndex]
        const targetMinute = minuteList[minuteIndex]
        const {fullDate, value: hourValue} = targetHour
        const startDate = new Date(`${fullDate} ${hourValue}:${targetMinute.value}`)
        const [h, m] = [startDate.getHours(), startDate.getMinutes()]
        const start_time_value = startDate.getTime()
        const {end_time, end_time_value} = this.getEndTime(start_time_value, currentHour)
        this.setData({
            start_time: `${this.patchZero(h)}:${this.patchZero(m)}`,
            start_time_value,
            end_time,
            end_time_value,
        })
    },
    pickerConfirm(ev) {
        const {currentHour} = this.data
        const {value} = ev.detail
        const [hour, minute] = value
        const {value: h, fullDate} = hour
        const {value: m} = minute
        const start_time = `${h < 10 ? '0' + h : h}:${m < 10 ? '0' + m : m}`
        const start_date = new Date(`${fullDate} ${start_time}`).getTime()
        const endTime = new Date(start_date + (currentHour * ONE_HOUR_VALUE))
        const [end_hour, end_minutes] = [endTime.getHours(), endTime.getMinutes()]
        const end_time = `${end_hour < 10 ? '0' + end_hour : end_hour}:${end_minutes < 10 ? '0' + end_minutes : end_minutes}`
        this.setData({
            start_time: start_time,
            end_time: end_time,
            start_time_value: start_date,
            end_time_value: endTime.getTime(),
            timePop: false,
        })
    },
    timestampNext(value) {
        const date = new Date(value)
        const [year, month, day, hour] = [date.getFullYear(), date.getMonth() + 1, date.getDate(), date.getHours()]
        const _date = new Date(`${year}/${month}/${day} ${hour}:00`)
        return _date.getTime() + 1000 * 60 * 60
    },
    patchZero(value) {
        return ('0' + value).slice(-2)
    },
    getEndTime(timestamp, hours) {
        const date = new Date(timestamp + (1000 * 60 * 60 * hours))
        const [hour, minutes] = [date.getHours(), date.getMinutes()]
        return {
            end_time: `${this.patchZero(hour)}:${this.patchZero(minutes)}`,
            end_time_value: date.getTime()
        }
    },
    patchTimeValue(timestamp, changeTime = false) {
        const minutes = Math.floor(timestamp / 1000 / 60 % 60)
        if (minutes + 5 >= 60) {
            timestamp = this.timestampNext(timestamp)
        }
        const date = new Date(timestamp)
        let [hour, y, m, d, minute] = [date.getHours(), date.getFullYear(), date.getMonth() + 1, date.getDate(), date.getMinutes()]
        const hourList = []
        for (let i = hour; i < 24; i++) {
            hourList.push({
                label: `${i}时`,
                value: i,
                fullDate: `${y}/${m}/${d}`,
                isCurrent: i === hour,
                minute
            })
        }
        const minuteList = this.getMinutesColumn(minute)
        if (changeTime) {
            const {currentHour} = this.data
            const [hourItem] = hourList
            const [minuteItem] = minuteList
            const start_str = `${hourItem.fullDate} ${hourItem.value}:${minuteItem.value}`
            const start_time_value = new Date(start_str).getTime()
            const {end_time, end_time_value} = this.getEndTime(start_time_value, currentHour)
            const v = `${hourItem.value}:${minuteItem.value}`
            this.setData({
                start_time: v,
                start_time_value,
                end_time,
                end_time_value
            })
        }
        return [hourList, minuteList]
    },
    getMinNumber(number) {
        const list = [0, 5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55]
        const len = list.length
        for (let i = 0; i < len; i++) {
            const target = list[i]
            if (target >= number) {
                return target
            }
        }
    },
    getMinutesColumn(minute) {
        let i = this.getMinNumber(minute)
        const result = []
        while (i < 60) {
            const value = this.patchZero(i)
            result.push({
                label: `${value}分`,
                value: `${value}`,
            })
            i += 5
        }
        return result
    },
    updateTimeColumn(timestamp) {
        const minutes = Math.floor(timestamp / 1000 / 60 % 60)
        if (minutes + 5 >= 60) {
            timestamp = this.timestampNext(timestamp)
        }
        const date = new Date(timestamp)
        return this.getMinutesColumn(date.getMinutes())
    },
    pickerColChange(ev) {
        const {column, value} = ev.detail
        if (column !== 0) return
        const {timeColumns} = this.data
        const [hourList] = timeColumns
        const targetHour = hourList[value]
        const {fullDate, value: hourValue} = targetHour
        const date = new Date(`${fullDate} ${hourValue}:${targetHour.isCurrent ? targetHour.minute : '00'}`)
        const minutesList = this.updateTimeColumn(date.getTime())
        this.setData({
            timeColumns: [hourList, minutesList]
        })
    },
    initColumn(timestamp, flag = false) {
        const resp = this.patchTimeValue(timestamp, flag)
        this.setData({
            timeColumns: resp
        })
    },
    initAllTime(id) {
        const date = new Date()
        const [year, month, day] = [date.getFullYear(), date.getMonth() + 1, date.getDate()]
        app.ajax({
            url: '/api/index/getAllTImes',
            data: {
                id,
                date: `${year}-${month}-${day}`,
            },
            success: res => {
                if (res.code === 1) {
                    this.setData({
                        allTimes: res.data
                    })
                    // this.getTimes()
                }
            }
        }, 1);
    },
    initWeekActive(selectstart) {
        const date = new Date(selectstart * 1000)
        const {weekData} = this.data
        const [m, d] = [date.getMonth() + 1, date.getDate()]
        const str = `${m < 10 ? '0' + m : m}.${d < 10 ? '0' + d : d}`
        weekData.forEach(item => {
            item.active = str === item.date
        })
        this.setData({
            weekData: [...weekData]
        })
    },
    initMealOption(room_id) {
        app.ajax({
            url: "/api/room/roomtaocan",
            data: {room_id},
            success: resp => {
                const {code, data, msg} = resp
                if (code !== 1) return toast({title: msg})
                if (!data || !data.length) return
                const mealData = data.map(item => {
                    const {taocan_price: price, id, time, name} = item
                    return {price, id, time, name}
                })
                this.setData({
                    mealOptions: mealData,
                })
            }
        })
    },
    initUserCoupon(cb) {
        app.initCouponData().then(resp => {
            const {coupon} = resp
            cb && cb()
            if (coupon.length) {
                this.setData({
                    couponList: coupon.map(item => {
                        const {title, money, min, id, coupon_id, expire, create_time} = item
                        const createTime = app.formatDate(create_time)
                        return {title, money, min, id, coupon_id, expire, createTime}
                    }),
                })
            }
        })
    },
    async initUserMoney() {
        const userData = await app.updateUserInfo()
        const {money: userMoney} = userData
        this.setData({userMoney})
    },
    initTotalPrice(priceValue) {
        const {timeList} = this.data
        const [target] = timeList
        const hour = target.value
        const totalPrice = (priceValue * hour).toFixed(2)
        this.setData({
            totalPrice,
        })
    },
    getRoomTimes(room_id, price) {
        function patchTime(times) {
            let result;
            if (typeof times === 'number') {
                result = [times]
            }
            if (typeof times === 'string') {
                result = times.split(',')
            }
            let max = 0, min = 0
            const timeList = result.map((item, index) => {
                const hour = item * 1
                if (index === 0) {
                    min = hour
                } else {
                    if (hour <= min) min = hour
                }
                if (hour >= max) max = hour
                return {
                    label: `${item}`,
                    value: hour,
                }
            })
            return {
                timeList,
                max,
                min,
            }
        }

        app.ajax({
            url: '/api/room/roomtimes',
            data: {room_id},
            success: resp => {
                const {code, data, msg} = resp
                if (code !== 1) return toast({title: msg}, () => wx.navigateBack())
                const {timeList, max, min} = patchTime(data)
                if (!timeList.length) return
                this.setData({timeList, minHour: min})
                console.log(timeList, 'timeList')
                const [target] = timeList
                const {value} = target
                this.setData({
                    activeTimeID: value,
                    currentHour: value,
                })
                this.initTotalPrice(price)
                this.initColumn(Date.now(), true)
                this.initOtherTimeList(max + 1)
            }
        })
    },
    //
    onLoad: function (options) {
        wx.showLoading({title: '正在获取', mask: true})
        const roomdetail = this.parseParams(options)
        if (!roomdetail) {
            wx.hideLoading()
            return toast({title: '未知错误'}, () => wx.navigateBack())
        }
        this.setData({roomdetail})
        this.initWeekData()
        this.getRoomTimes(roomdetail.id, roomdetail.price)
        this.initMealOption(roomdetail.id)
        this.initUserCoupon(async () => {
            await delay(300)
            wx.hideLoading()
        })
    },
    onShow() {
        this.initUserMoney().catch(null)
    },
    parseParams(options) {
        if (!options.hasOwnProperty('info')) return toast({title: '参数错误'}, () => wx.navigateBack())
        let roomdetail;
        try {
            roomdetail = JSON.parse(options.info)
        } catch (e) {
            roomdetail = JSON.parse(decodeURIComponent(options.info))
        }
        return roomdetail
    },
    choseTimeCancel() {
        this.setData({
            timePop: false
        })
    },
    onUnload() {
        if (this.data.bindEvent) {
            EventBus.$off('accountSuccess', this.updateMoney)
        }
    },
    previewImage() {
        const {roomdetail} = this.data
        wx.previewImage({
            urls: [roomdetail.image]
        })
    },
    // 确定选择的时间戳
    // getTimeSlot() {
    //     const {weekData, start_time, end_time, allTimes, currentHour} = this.data
    //     const targetDay = weekData.find(item => item.active)
    //     if (!targetDay) return toast({title: "时间选择错误"})
    //     const {fullTime} = targetDay
    //     const start = `${fullTime} ${start_time}`
    //     const start_value = new Date(start).getTime()
    //     const end_value = start_value + (ONE_HOUR_VALUE * currentHour)
    //     const result = []
    //     for (const key in allTimes) {
    //         const target = allTimes[key]
    //         const {local_time} = target
    //         const time = new Date(local_time)
    //         if (time >= start_value && time <= end_value) {
    //             result.push(key)
    //         }
    //     }
    //     return {
    //         result,
    //         date: start
    //     }
    // },
})
